﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Admin.Domain;

namespace Windows.Admin.Infrastructure.EFCore.Extensions
{
    public static class EmployeeExtension
    {
        public static IQueryable<Employee> GetByOrganizationId(this IQueryable<Employee> query, long organizationId)
        {
            var obj = from a in query
                      from b in a.Organization_Employees.DefaultIfEmpty()
                      where (b.Organization!.Level != null && ("," + b.Organization!.Level + ",").Contains("," + organizationId + ",")) || b.OrganizationId == organizationId
                      select a;
            return obj.Distinct();

        }
        public static IQueryable<Employee> GetByPostId(this IQueryable<Employee> query, long postId)
        {
            var obj = from a in query
                      from b in a.Post_Employees.DefaultIfEmpty()
                      where b.PostId == postId
                      select a;
            return obj.Distinct();
        }
    }
}
